package com.panda.rentHouse.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.panda.common.controller.BaseController;
import com.panda.common.util.Pager;
import com.panda.rentHouse.service.MenuService;

@RestController
@RequestMapping("/rentHouse/menu")
public class MenuController extends BaseController {
	
	@Autowired
	private MenuService menuService;
	
	/**
	 * 获取左侧菜单数据
	 * @param req
	 * @param res
	 * @return
	 */
	@RequestMapping("/getMenuList")
	public Map<String,Object> getMenuList(HttpServletRequest req, HttpServletResponse res){
		logger.info("execute the MenuController 's getMenuList method...");
		Map<String,Object> map = new HashMap<String, Object>();
		List<Map<String,Object>> data = null;
		try {
			data = menuService.getMenuList();
			map = super.getSuccessResultMap("ok", data, data.size());
		} catch (Exception e) {
			e.printStackTrace();
			map = super.getErrorResultMap("fail");
		}
		return map;
	}
	
	/**
	 * 获取菜单列表
	 * @param req
	 * @param res
	 * @return
	 */
    @RequestMapping(value = "/menuList")
    public Map<String,Object> menuList(HttpServletRequest req, HttpServletResponse res){
    	logger.info("execute the MenuController 's menuList method...");
    	Map<String,Object> map = new HashMap<String, Object>();
    	Map<String,Object> params = new HashMap<String, Object>();
    	try {
			int pageNo = super.getInt(req, "page", 1);
			int pageSize = super.getInt(req, "limit", 10);
			int status = super.getInt(req, "status", -1);
			String searchValue = super.getString(req, "searchValue", "");
			params.put("status", status);
			params.put("searchValue", searchValue);
			Pager pager = menuService.getMenuPager(params, pageNo, pageSize);
			map = super.getSuccessResultMap("ok", pager.getData(),pager.getTotalRecord());
		} catch (Exception e) {
			e.printStackTrace();
			map = super.getErrorResultMap("fail");
		}
        return map;
    }

}
